#include <bits/stdc++.h>
using namespace std;
int n, m, w[30], v[30], f[50001];
int main(){
	cin >> m >> n;
	for(int i = 1; i <= n; i++){
		scanf("%d %d", &v[i], &w[i]);
		w[i] *= v[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = m; j >= v[i]; j--){
			if(j>=v[i])
            {
                f[j]=max(f[j],f[j-v[i]]+w[i]);
            }
		}
	}
	cout << f[m] << endl;
	return 0;
}
